﻿using System;
using System.Linq;
using System.Xml.Linq;

namespace _130_使用LINQ将序列转换为XML文档_LINQ语法
{
    class Program
    {
        static void Main(string[] args)
        {
            Account[] 数组 =
            {
                new Account
                {
                    UserID=1,
                    UserName="user 1",
                    Password="123",
                    IsAdmin=false
                },
                new Account
                {
                    UserID=2,
                    UserName="user 2",
                    Password="678",
                    IsAdmin=false
                },
                new Account
                {
                    UserID=3,
                    UserName="user 3",
                    Password="hjk",
                    IsAdmin=true
                }

            };

            var 查询 = from a in 数组
                     select new XElement("account",
                     new XAttribute("user_id", a.UserID),
                     new XAttribute("user_name", a.UserName),
                     new XAttribute("password", a.Password),
                     new XAttribute("is_admin", a.IsAdmin));

            XElement 文档根元素 = new XElement("数组", 查询);
            //创建文档对象
            XDocument 文档对象 = new XDocument(文档根元素);

            Console.WriteLine(文档对象);


        }
    }


    public class Account
    {
        public int UserID { get; set; }
        public String UserName { get; set; }
        public string  Password { get; set; }
        public bool IsAdmin { get; set; }
    }
}
